package com.sinoeyes.flowdata.service.impl;

import com.sinoeyes.common.core.page.RestPageResult;
import com.sinoeyes.common.core.text.Convert;
import com.sinoeyes.common.vo.BaseVo;
import com.sinoeyes.flowdata.po.FlowSalesDataPo;
import com.sinoeyes.flowdata.po.FlowStoreDataPo;
import com.sinoeyes.flowdata.filter.FlowStoreDataFilter;
import com.sinoeyes.flowdata.mapper.FlowStoreDataMapper;
import com.sinoeyes.flowdata.service.IFlowStoreDataService;
import com.sinoeyes.flowdata.vo.FlowStoreDatasVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 标准库存流向Service业务层处理
 * 
 * @author steven.zhang
 * @date 2019-10-10
 */
@Service
public class FlowStoreDataServiceImpl implements IFlowStoreDataService
{
    @Autowired
    private FlowStoreDataMapper flowStoreDataMapper;

    /**
     * 查询标准库存流向
     * 
     * @param id 标准库存流向ID
     * @return 标准库存流向
     */
    @Override
    public FlowStoreDatasVo selectFlowStoreDatasById(String id)
    {
        return BaseVo.copyPo2Vo(flowStoreDataMapper.selectFlowStoreDatasById(id), FlowStoreDatasVo.class);
    }

    /**
     * 新增标准库存流向
     * 
     * @param flowStoreDataVo 标准库存流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int insertFlowStoreDatas(FlowStoreDatasVo flowStoreDataVo)
    {
        return flowStoreDataMapper.insertFlowStoreDatas(BaseVo.copyVo2Po(flowStoreDataVo, FlowStoreDataPo.class));
    }

    /**
     * 修改标准库存流向
     * 
     * @param flowStoreDataVo 标准库存流向
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int updateFlowStoreDatas(FlowStoreDatasVo flowStoreDataVo)
    {
        return flowStoreDataMapper.updateFlowStoreDatas(BaseVo.copyVo2Po(flowStoreDataVo, FlowStoreDataPo.class));
    }

    /**
     * 删除标准库存流向对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowStoreDatasByIds(String ids)
    {
        return flowStoreDataMapper.deleteFlowStoreDatasByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除标准库存流向信息
     * 
     * @param id 标准库存流向ID
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int deleteFlowStoreDatasById(String id)
    {
        return flowStoreDataMapper.deleteFlowStoreDatasById(id);
    }

    /**
     * 根据过滤条件查询
     * @param flowStoreDataFilter
     * @return
     */
    @Override
    public RestPageResult<FlowStoreDatasVo> selectFlowStoreDatasByFilter(FlowStoreDataFilter flowStoreDataFilter) {
        flowStoreDataFilter.startPage();
        List<FlowStoreDataPo> flowStoreDataPos = flowStoreDataMapper.selectFlowStoreDatasByFilter(flowStoreDataFilter);
        RestPageResult pageResult = flowStoreDataFilter.getPageResult(flowStoreDataPos);
        return BaseVo.copyPo2Vo(pageResult, FlowStoreDatasVo.class);
    }
}
